$.ajax({
    type: 'POST',
    url: '/isLogin',
    async: false,
    data: {},
    dataType: 'json',
    success: function (result) {
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (XMLHttpRequest.status==555){
            var layer;
            layui.use(['layer', 'form'], function(){
                layer = layui.layer
                layer.alert('未登录,请登录后操作',{icon:7}, function(index){
                    //do something
                    layer.close(index);
                    top.location.href="/login";
                });
            });
        }else{
            console.log(XMLHttpRequest.status)
            var layer;
            layui.use(['layer', 'form'], function(){
                layer = layui.layer
                layer.alert('页面加载失败',{icon:7}, function(index){
                    //do something
                    layer.close(index);
                });
            });
        }
    },
});
var width=$('.layui-table-body').width();
layui.use('laydate', function() {
    var laydate = layui.laydate;
    laydate.render({
        elem: '#demoReload'
        ,type:'month'
    });
});
layui.use('table', function(){
    var table = layui.table;
    //方法级渲染
    table.render({
        elem: '#LAY_table_user'
        ,url: "/report/getMerchantMonthData"
        ,cols: [[
            // {field:'id', title: '序号', width:width*0.25 }
            {field:'merchantname', title: '账户名称', width:width*0.25}
            ,{field:'eleccost', title: '电费', width:width*0.25, sort: true}
            ,{field:'elecusage', title: '用电量', width:width*0.25, sort: true}
            ,{field:'watercost', title: '水费', width:width*0.25, sort: true}
            ,{field:'waterusage', title: '用水量', width:width*0.25, sort: true}
            ,{field:'gascost', title: '燃气费', width:width*0.25, sort: true}
            ,{field:'gasusage', title: '燃气用量', width:width*0.25, sort: true}
            ,{field:'aftersettle', title: '账户余额', width:width*0.25}
        ]]
        ,id: 'testReload'
        ,page: true
        ,height: 522
        ,response: {
            statusCode: 666
        }
        // ,even:true //每行条纹
        ,limits: [10,15,20,25,30]
        ,limit: 10 //每页默认显示的数量
        ,toolbar:'#toolbarDemo'  //导出打印
        ,parseData:function (res) {
            return{
                "code":res.code,
                "msg":res.msg,
                "count":res.data.settlementList.length,
                "data":res.data.settlementList
            };
        }
        , done: function(res, curr, count){
        }
    });
    var $ = layui.$, active = {
        reload: function(){
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    ym: demoReload.val()
                }
            });
        }
    };

    $('#query').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    //监听行单击事件（单击事件为：rowDouble）
    //其中的user对应的是 table中的lay-filter="user"
    table.on('row(user)', function(obj){
        var data = obj.data;
        var id=data['id'];
        // layer.alert(JSON.stringify(data.id));
        // window.location.href="{:U('Company_Charging/Query')}&id="+id;
        //标注选中样式
        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
    });

});